<?php
include_once('common.inc.php');
class ELGG {
	private $_db;
	private $time;

	function __construct() {
		global $db;
		$this->_db = $db;
		$this->time  = time();

	}
	function add_user($row){
		$sql = "INSERT INTO elgg_users
				(ident, username, password, email, name, icon, active, alias, code, icon_quota, file_quota,template_id, owner, user_type, moderation, last_action, template_name) 
				VALUES 
				(NULL, '{$row['username']}', '{$row['password']}', '{$row['email']}', '{$row['name']}', -1, 'yes', '', '', 10, 1000000000, -1, -1, 'person', 'no', 0, 'Default_Template')";
		$rs = $this->_db->query($sql);
		if ($num = $this->_db->insert_id()) {
			return true;
		}
	}
	function add_post($row){

		$sql = "INSERT INTO elgg_weblog_posts
				(ident, owner, weblog, icon, access, posted, title, body) VALUES 
				(NULL, {$row['owner']}, {$row['weblog']}, -1, '{$row['access']}', {$this->time}, '{$row['title']}', '{$row['body']}');";
		$rs = $this->_db->query($sql);
		if ($num = $this->_db->insert_id()) {
			return true;
		}
	}
}

//$elgg = new ELGG();

//$row['username'] = 'qiang';
//$row['password'] = md5('qiangqiang');
//$row['email'] = 'qiang@qiang.com';
//$row['name'] = 'qiang';

//$elgg->add_user($row);


/*$row['owner'] = 1;
$row['weblog'] = 1;
$row['access'] = 'PUBLIC';
$row['title'] = 'title';
$row['body'] = 'body body';
if ($elgg->add_post($row)){
	echo "添加成功";
}*/
?>